<?php

	if (!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME']))
		die ('Please do not load this page directly. Thanks!');

	if ( post_password_required() ) { ?>
		<?php _e("This post is password protected. Enter the password to view comments."); ?>
	<?php
		return;
	}
?>


<div id="userloggedin" style="display:none;"><?php echo is_user_logged_in() ?></div>

<script type="text/javascript">
	function validate_comment_field(){
		var erros = 0;
		if ($('#userloggedin').html() != "1"){
			<!-- nome -->
			if ( $('#author').val() == "" ){
				erros++;
				alert('<?php _e("Error: please fill the required field [name]."); ?>');
			}
			<!-- email -->
			if ( $('#email').val() == "" ){
				erros++;
				alert('<?php _e("Error: please fill the required field [email]."); ?>');
			} else {
				if (validate_email($('.emaildoform').val()) == 0){
					erros++;
					alert('<?php _e("Please provide a valide email address."); ?>');
				}
			}
			<!-- message -->
			if ( $('#comment').val() == "" ){
				erros++;
				alert('<?php _e("You forgot to leave your message. Please do so."); ?>');
			}
		}
		if (erros == 0){
			$('#submit').click();
		}
	}
</script>

<?php if ( have_comments() ) : ?>
	
	<div class="navigation">
		<div class="next-posts"><?php previous_comments_link() ?></div>
		<div class="prev-posts"><?php next_comments_link() ?></div>
	</div>

	<div class="commentlist"><?php wp_list_comments(array('style' => 'div', 'avatar_size' => 52,'type'=>'comment', 'callback'=>'arc_comment')); ?></div>

	<div class="navigation">
		<div class="next-posts"><?php previous_comments_link() ?></div>
		<div class="prev-posts"><?php next_comments_link() ?></div>
	</div>
	
 <?php else : // this is displayed if there are no comments so far ?>

	<?php if ( comments_open() ) : ?>
		<!-- If comments are open, but there are no comments. -->

	 <?php else : // comments are closed ?>
		<p><?php _e("Comments are closed."); ?></p>

	<?php endif; ?>
	
<?php endif; ?>

<?php if ( comments_open() ) : ?>

<div id="respond">

	<div class="leavacomment"><?php comment_form_title( 'Leave a Comment', 'Leave a Comment to %s' ); ?></div>

	<div class="cancel-comment-reply">
		<?php cancel_comment_reply_link(); ?>
	</div>

	<?php if ( get_option('comment_registration') && !is_user_logged_in() ) : ?>
		<p><?php _e("You must be"); ?> <a href="<?php echo wp_login_url( get_permalink() ); ?>"><?php _e("logged in"); ?></a> <?php _e("to post a comment."); ?></p>
	<?php else : ?>

	<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">

		<?php if ( is_user_logged_in() ) : ?>

			<p><?php _e("Logged in as"); ?> <a href="<?php echo get_option('siteurl'); ?>/wp-admin/profile.php"><?php echo $user_identity; ?></a>. <a href="<?php echo wp_logout_url(get_permalink()); ?>" title="Log out of this account"><?php _e("Log out"); ?> &raquo;</a></p>

		<?php else : ?>

			<div class="name">
				<label for="author"><?php _e("Name"); ?> <?php if ($req) _e("(required)"); ?></label><br/>
				<input type="text" name="author" id="author" value="<?php echo esc_attr($comment_author); ?>" size="31" tabindex="1" <?php if ($req) echo "aria-required='true'"; ?> />
			</div>

			<div>
				<label for="email"><?php _e("Email (will not be published)"); ?> <?php if ($req) _e("(required)"); ?></label><br/>
				<input type="text" name="email" id="email" class="emaildoform" value="<?php echo esc_attr($comment_author_email); ?>" size="34" tabindex="2" <?php if ($req) echo "aria-required='true'"; ?> />
			</div><br/>

			<div>
				<label for="url"><?php _e("Website"); ?></label><br/>
				<input type="text" name="url" id="url" value="<?php if (esc_attr($comment_author_url) == "") echo "http://"; else echo esc_attr($comment_author_url); ?>" size="71" tabindex="3" />
			</div><br/>

		<?php endif; ?>

		<div>
			<textarea name="comment" id="comment" cols="69" rows="10" tabindex="4"></textarea>
		</div>

		<div>
			<input name="submit_engodo" id="submit_engodo" type="button" tabindex="5" value="<?php _e("Submit Comment"); ?>" onclick="validate_comment_field()"/>
			<input name="submit" id="submit" type="submit" />
			<?php comment_id_fields(); ?>
		</div>
		
		

	</form>

	<?php endif; // If registration required and not logged in ?>
	
</div>

<?php endif; ?>


<?php 

function arc_comment($comment, $args, $depth) {
   $GLOBALS['comment'] = $comment; ?>
   <div <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
     <div id="comment-<?php comment_ID(); ?>">
      <div class="comment-author vcard">
         <div><?php echo get_avatar($comment,$size='52',$default= get_template_directory_uri().'/img/foto1.jpg' ); ?></div>
		
		<div style="margin-left: 65px;">
         <div class="comment_text"> <?php comment_text() ?> </div>
         
          <div class="comment-meta commentmetadata"><?php printf('<span class="fn comment_author">%s</span>', get_comment_author_link()) ?><a class="comment_date" href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"><?php printf('%1$s at %2$s  &#8226;', get_comment_date(),  get_comment_time()) ?></a>
      
      <span class="reply">
         <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
      </span>
      
      <span class="comment-edit">
      	<?php edit_comment_link('[Edit]','  ','') ?></div>
	</span>
     </div>
  </div>
      </div>
      <?php if ($comment->comment_approved == '0') : ?>
         <em><?php _e('Your comment is awaiting moderation.') ?></em>
         <br />
      <?php endif; ?>

     
<?php
        } 

?>


